package dp.numberOfArithemticSlices;
/**
 * @Date 2020/04/20
 * @author 王光浩 
 * @Thinking 使用备忘录
 */
public class MyMethodTwo {
	public int numberOfArithmeticSlices(int[] A) {
		if(A.length<2 || A==null) return 0;
		int sum = 0;		 //返回值
		int count = 2;		 //等差数列值的个数
		int d = A[1]-A[0];   //等差值
		int number = 0;      //等差数组个数的累加器
		for(int i=2 ; i<A.length ; i++) {
			if( count>=3 ) number += count-2;
			if( A[i]-A[i-1]!=d ) {
				//将等差数列值的个数重置，等差值重置
				count = 2;
				d = A[i]-A[i-1];
				//将上一个等差数组的个数累加到sum中，累加器清零
				sum += number;   
				number = 0;  
			}
			else count++;
		}
		if( count>=3 ) number += count-2;
		sum += number;
		return sum;
    }
}
